// 使用spawn创建新线程,主线程完成新线程也会被结束
use std::thread;
use std::time::Duration;

fn main() {
    // 使用 join 等待所有线程结束
    let handle = thread::spawn(|| {
        for i in 1..10 {
            println!("h1 number {} from the spawned thread!", i);
            thread::sleep(Duration::from_millis(1));
        }
    });

    for i in 1..5 {
        println!("h1 number {} from the main thread!", i);
        thread::sleep(Duration::from_millis(1));
    }
    //位置会影响线程执行顺序
    handle.join().unwrap();
}
